angular.module('app-util-func', [
    'wechat-func'
    'order-util'
    'datepicker-util'
])
#公用的方法

.service 'popup', ($ionicPopup) ->
    {
        error: (msg) ->
            $ionicPopup.alert {title: '温馨提示', template: msg}
        info: (msg) ->
            $ionicPopup.alert {title: '温馨提示', template: msg}
    }

.factory 'validator', ->
    phone: (phone) ->
        /^0?(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/.test phone

.factory 'guid', ($localStorage) ->
    guid = $localStorage.get 'wf-guid'
    if _.isEmpty(guid)
        guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) ->
            r = Math.random() * 16 | 0
            v = if c == 'x' then r else (r & 0x3 | 0x8)
            v.toString(16)
        $localStorage.set 'wf-guid', guid
    guid
.service 'userData', ($localStorage,$http,$q) ->
    getToken: -> $localStorage['token']
    setToken: (token) -> $localStorage['token']=token
    reset: ->
        $localStorage['user']=null
        $localStorage['token']=null
    get  : -> angular.copy $localStorage['user']
    set  : (user) ->
        $localStorage['user']=user
